//# sourceURL=http://uMapApp/Module/StakeNum/Mileage
define([], function () {

        function Mileage(option) {
            var _this = this;

            if (option !== undefined) {

                if (option.constructor.name === "Mileage") {

                    _this._distance = option.distance;
                    _this.updateDistance();

                } else if (option.constructor.name === "String") {

                    _this._str = option;
                    _this.updateStr();

                } else if (option.constructor.name === "Number") {

                    _this._distance = option;
                    _this.updateDistance();

                } else if (option.distance) {

                    _this._distance = option.distance;
                    _this.updateDistance();
                }

            }
        }

        var _class = Mileage;

        Object.defineProperties(_class.prototype, {
            "no"               : {
                set : function (no) {
                    var _this = this;
                    _this._no = no;
                    _this.updateNoExtend();
                },
                get : function () {
                    return this._no;
                }
            }
            , "extend"         : {
                set : function (extend) {
                    var _this = this;
                    _this._extend = extend;
                    _this.updateNoExtend();
                },
                get : function () {
                    return this._extend;
                }
            }
            , "distance"       : {
                set : function (distance) {
                    var _this = this;
                    _this._distance = distance;
                    _this.updateDistance();
                },
                get : function () {
                    return this._distance;
                }
            }
            , "str"            : {
                set : function (str) {
                    var _this = this;
                    _this._str = str;
                    _this.updateStr();
                },
                get : function () {
                    return this._str;
                }
            }
            , "updateDistance" : {
                value : function () {

                    var _this = this;
                    _this._distance = Number(_this._distance);

                    if (!isNaN(_this._distance) && _this._distance >= 0) {

                        _this._distance = Math.round(_this._distance);
                        _this._no = Math.floor(_this._distance / 1000);
                        _this._extend = _this._distance - _this._no * 1000;

                        var extendStr = "";

                        if (_this._extend !== 0) {
                            extendStr = "+" + String(_this._extend + 1000).substr(1, 3);
                        }

                        _this._str = "K" + _this._no + extendStr;
                    }
                }
            }
            , "updateStr"      : {
                value : function () {

                    var _this = this;
                    var pattern = /(K|k)\d{1,}(\+\d{1,3})*/;

                    if (pattern.test(_this._str)) {
                        _this._str = _this._str.replace(/K|k/, "K");
                        _this.distance = Number(_this._str.split("+")[0].split("K")[1]) * 1000 + Number(_this._str.split("+")[1] || 0);
                    }
                }
            }
            , "updateNoExtend" : {
                value : function () {
                    var _this = this;

                    _this._extend = _this._extend || 0;
                    if (_this.no) {
                        _this.distance = _this._no * 1000 + _this._extend;
                    }

                }
            }
        });

        return _class;

    }
);